/*
	---------------------------------------------
	-	Context menu stuff
	-	/context.js
	---------------------------------------------
	-	Author:	James Haley
	-			jameshaley@sevendigits.com
	-			2011
	---------------------------------------------
*/
	var seven={}; // SevenDigits
	
	//	++ Context Management
	//----------------------------------------------
		(seven.context = function() {
			return {
				currentPop:null,
				currentEl:null,
				elementsList:[],
				add:function(){
					// Clean previous if required
					($('oSevenExtEmDisplay'))?$('oSevenExtEmDisplay').remove():null;
					seven.context.currentEl=null
					
					// Next, go for events
					var oElements = document.getElementsByTagName('*');
					
					$A(oElements).each(function(o){
						seven.context.elementsList.push(o);
						o.setStyle({"outline":"none"});
						
						o.observe('mouseover',function(o){
							$(Event.element(event)).setStyle({"outline":"5px SOLID #CC0000"});
							Event.stop(o);
						});
						o.observe('mouseout',function(o){
							$(Event.element(event)).setStyle({"outline":"none"});
							Event.stop(o);
						});
						o.observe('click',function(o){
							Event.stop(o);
							seven.context.selectedE($(Event.element(o)));
						});
					});
				},
				selectedE:function(o){
					seven.context.elementsList.each(function(oEL){$(oEL).stopObserving();});
					seven.context.currentEl=o;
					o.setStyle({"outline":"5px SOLID #FF0076"});
					seven.context.notify.create(o)
				},
				notify:function(){
					return {
						create:function(o){
							var oPos = o.cumulativeOffset(),
								nBase = parseInt(nDefaultBase),
								oSize = {"height":o.offsetHeight,"width":o.offsetWidth,"heightEm":(o.offsetHeight/nBase),"widthEm":(o.offsetWidth/nBase)},
								oDisplay = new Element('div',{id:'oSevenExtEmDisplay'}).setStyle({"position":"fixed","left":"1em","top":"1em","text-align":"left","padding":"1em","backgroundColor":"rgba(255,0,118,0.9)","zIndex":900000,"borderRadius":"0.5em"}).update('<div style="float:left;"><h4 style="font-size: 20px;margin:0 0 10px 0; color: #FFF;">Width: '+oSize.widthEm.tidyDecimal(2)+'em ('+oSize.width+'px) &mdash; Height: '+oSize.heightEm.tidyDecimal(2)+'em ('+oSize.height+'px)</h4><h5 style="margin:0;color: #FFF;font-size: 12px;font-weight:normal;">NB: This is calculated using a base font size of: <strong style="color:#FFF;">'+nBase+'px</strong>. You can customise this within the extension.</h5></div>'),
								oClose = new Element('div').setStyle({"paddingLeft":"10px","marginLeft":"10px","float":"right","borderLeft":"2px SOLID rgba(255,255,255,0.5)"}).update('<a href="javascript:void(0);" style="color: #FFF;font-size: 15px;">Close</a>');
								
								oClose.down('a').observe('click',function(){seven.context.notify.remove(o);});
							oDisplay.insert({"top":oClose});
							document.body.appendChild(oDisplay);
							
							oDisplay.appear({duration:0.3});
						},
						remove:function(o){
							$('oSevenExtEmDisplay').hide();
							seven.context.elementsList.each(function(oEL){$(oEL).setStyle({"outline":"none"});});
						}
					}
				}()
			}
		}());
	
	seven.context.add();
	
	// Prototype
	Number.prototype.tidyDecimal = function(n) {
		return Math.abs(this.toFixed(n));
	}
	
	